package com.sline.chario;

import java.io.File;
import java.util.Scanner;

public class Demo7_Digui {
    public static void main(String[] args) {
//        System.out.println(fun(8));
        File dir = enterDir();
        getJava(dir);
    }

    public static int fun(int a) {
        if (a == 1) {
            return a;
        } else {
            return a * fun(a - 1);
        }
    }

    public static File enterDir() {
        Scanner sc = new Scanner(System.in);

        while (true) {
            String dirStr = sc.nextLine();
            File dir = new File(dirStr);
            if (!dir.exists()) {
                System.out.println("您输入的目录有误, 请重新输入~");
            } else if (dir.isFile()) {
                System.out.println("您输入的是文件路径, 请重新输入~");
            } else if (dir.isDirectory()) {
                return dir;
            }
        }
    }

    public static void getJava(File dir) {
        File[] subFiles = dir.listFiles();
        for (File subFile: subFiles) {
            if (subFile.isFile() && subFile.getName().endsWith(".java")) {
                System.out.println(subFile.getName());
            } else if (subFile.isDirectory()) {
                getJava(subFile);
            }
        }
    }
}
